package com.Lixiaoqian.PartyHistoryMuseum.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.Lixiaoqian.PartyHistoryMuseum.R;
import com.Lixiaoqian.PartyHistoryMuseum.bean.BannerBean;
import com.Lixiaoqian.PartyHistoryMuseum.net.ApiConstant;
import com.Lixiaoqian.PartyHistoryMuseum.utils.DensityUtil;
import com.Lixiaoqian.PartyHistoryMuseum.utils.LoadImageUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by huangzhibo on 2017/9/12/012.
 * mail:1043202454@qq.com
 */

public class BannerAdapter extends RecyclerView.Adapter<BannerAdapter.ViewHolder> {

    private List<BannerBean> data;
    private Context context;
    public BannerAdapter(Context context,List<BannerBean> data) {
        this.context=context;
        this.data = data;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item_banner, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        BannerBean bannerBean = data.get(position);
        holder.tvTitle.setText(bannerBean.getSourcename());
        holder.tvAuthor.setText(bannerBean.getSourcedesc());
        LoadImageUtils.LoadImg(context, ApiConstant.IMAGE_BASE_URL+bannerBean.getCover_image(),holder.ivThem
        , DensityUtil.dip2px(context,86),DensityUtil.dip2px(context,86));
    }


    @Override
    public int getItemCount() {
        return data.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_them)
        ImageView ivThem;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_author)
        TextView tvAuthor;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


}
